preorder = [3, 9, 20, 15, 7], inorder = [9, 3, 15, 20, 7]

var buildTree = function (preorder, inorder) {
    if (preorder.length === 0) return null;
    let rootVal = preorder.shift()
    let index = inorder.indexOf(rootVal)
    let root = new TreeNode(rootVal)
    root.left = buildTree(preorder.slice(0, index), inorder.slice(0, index))
    root.right = buildTree(preorder.slice(index), inorder.slice(index + 1))
    return root
}